home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 4 / QRZ Ham Radio Callsign Database - Volume 4.iso / files / tcpip / amiga / asrc29p.lha / tcp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-29  |  8.6 KB  |  261 lines

  1. /* TCP implementation. Follows RFC 793 as closely as possible */
  2. #ifndef    NULLTCB
  3.  
  4. #include "global.h"
  5. #include "netuser.h"
  6. #include "timer.h"
  7. #include "internet.h"
  8.  
  9. #define    DEF_WND    2048    /* Default receiver window */
  10. #define    NTCB    19    /* # TCB hash table headers */
  11. #define    RTTCACHE 16    /* # of TCP round-trip-time cache entries */
  12. #define DEF_RETRIES 5   /* default number of retries before resetting tcb */
  13. #define    DEF_MSS    512    /* Default maximum segment size */
  14. #define    DEF_RTT    5000    /* Initial guess at round trip time (5 sec) */
  15. #define    MSL2    30    /* Guess at two maximum-segment lifetimes */
  16.  
  17. extern int32 Clock;
  18. #define    geniss()    ((int32)Clock << 18)    /* Increment clock at 4.5 Mbytes/sec */
  19.  
  20. /* Round trip timing parameters */
  21. #define    AGAIN    8    /* Average RTT gain = 1/8 */
  22. #define    LAGAIN    3    /* Log2(AGAIN) */
  23. #define    DGAIN    4    /* Mean deviation gain = 1/4 */
  24. #define    LDGAIN    2    /* log2(DGAIN) */
  25.  
  26. /* TCP segment header -- internal representation
  27.  * Note that this structure is NOT the actual header as it appears on the
  28.  * network (in particular, the offset and checksum fields are missing).
  29.  * All that knowledge is in the functions ntohtcp() and htontcp() in tcpsubr.c
  30.  */
  31. struct tcp {
  32.     int16 source;    /* Source port */
  33.     int16 dest;    /* Destination port */
  34.     int32 seq;    /* Sequence number */
  35.     int32 ack;    /* Acknowledgment number */
  36.     struct {
  37.         char urg;
  38.         char ack;
  39.         char psh;
  40.         char rst;
  41.         char syn;
  42.         char fin;
  43.     } flags;
  44.     int16 wnd;    /* Receiver flow control window */
  45.     int16 up;    /* Urgent pointer */
  46.     int16 mss;    /* Optional max seg size */
  47. };
  48. /* TCP options */
  49. #define    EOL_KIND    0
  50. #define    NOOP_KIND    1
  51. #define    MSS_KIND    2
  52.  
  53. #define    TCPLEN        20
  54. #define    MSS_LENGTH    4
  55. /* Resequencing queue entry */
  56. struct reseq {
  57.     struct reseq *next;    /* Linked-list pointer */
  58.     struct tcp seg;        /* TCP header */
  59.     struct mbuf *bp;    /* data */
  60.     int16 length;        /* data length */
  61.     char tos;        /* Type of service */
  62. };
  63. #define    NULLRESEQ    (struct reseq *)0
  64.  
  65. /* TCP connection control block */
  66. struct tcb {
  67.     struct tcb *prev;    /* Linked list pointers for hash table */
  68.     struct tcb *next;
  69.  
  70.     struct connection conn;
  71.  
  72.     char state;    /* Connection state */
  73.  
  74. /* These numbers match those defined in the MIB for TCP connection state */
  75. #define    TCP_CLOSED        1
  76. #define    TCP_LISTEN        2
  77. #define    TCP_SYN_SENT        3
  78. #define    TCP_SYN_RECEIVED    4
  79. #define    TCP_ESTABLISHED        5
  80. #define    TCP_FINWAIT1        6
  81. #define    TCP_FINWAIT2        7
  82. #define    TCP_CLOSE_WAIT        8
  83. #define    TCP_LAST_ACK        9
  84. #define    TCP_CLOSING        10
  85. #define    TCP_TIME_WAIT        11
  86.  
  87.     char reason;        /* Reason for closing */
  88. #define    NORMAL        0    /* Normal close */
  89. #define    RESET        1    /* Reset by other end */
  90. #define    TIMEOUT        2    /* Excessive retransmissions */
  91. #define    NETWORK        3    /* Network problem (ICMP message) */
  92.  
  93. /* If reason == NETWORK, the ICMP type and code values are stored here */
  94.     char type;
  95.     char code;
  96.  
  97.     /* Send sequence variables */
  98.     struct {
  99.         int32 una;    /* First unacknowledged sequence number */
  100.         int32 nxt;    /* Next sequence num to be sent for the first time */
  101.         int32 ptr;    /* Working transmission pointer */
  102.         int32 wl1;    /* Sequence number used for last window update */
  103.         int32 wl2;    /* Ack number used for last window update */
  104.         int16 wnd;    /* Other end's offered receive window */
  105.         int16 up;    /* Send urgent pointer */
  106.     } snd;
  107.     int32 iss;        /* Initial send sequence number */
  108.     int32 resent;        /* Count of bytes retransmitted */
  109.     int16 cwind;        /* Congestion window */
  110.     int16 ssthresh;        /* Slow-start threshold */
  111.  
  112.     /* Receive sequence variables */
  113.     struct {
  114.         int32 nxt;    /* Incoming sequence number expected next */
  115.         int16 wnd;    /* Our offered receive window */
  116.         int16 up;    /* Receive urgent pointer */
  117.     } rcv;
  118.     int32 irs;        /* Initial receive sequence number */
  119.     int32 rerecv;        /* Count of duplicate bytes received */
  120.     int16 mss;        /* Maximum segment size */
  121.  
  122.     int16 window;        /* Receiver window and send queue limit */
  123.  
  124.     void (*r_upcall) __ARGS((struct tcb *tcb,int cnt));
  125.         /* Call when "significant" amount of data arrives */
  126.     void (*t_upcall) __ARGS((struct tcb *tcb,int cnt));
  127.         /* Call when ok to send more data */
  128.     void (*s_upcall) __ARGS((struct tcb *tcb,int old,int new));
  129.         /* Call when connection state changes */
  130.     struct {        /* Control flags */
  131.         char force;    /* We owe the other end an ACK or window update */
  132.         char clone;    /* Server-type TCB, cloned on incoming SYN */
  133.         char retran;    /* A retransmission has occurred */
  134.         char active;    /* TCB created with an active open */
  135.         char synack;    /* Our SYN has been acked */
  136.         char rtt_run;    /* We're timing a segment */
  137.     } flags;
  138.     char tos;        /* Type of service (for IP) */
  139.     char backoff;        /* Backoff interval */
  140.  
  141.     struct mbuf *rcvq;    /* Receive queue */
  142.     struct mbuf *sndq;    /* Send queue */
  143.     int16 rcvcnt;        /* Count of items on rcvq */
  144.     int16 sndcnt;        /* Number of unacknowledged sequence numbers on
  145.                  * sndq. NB: includes SYN and FIN, which don't
  146.                  * actually appear on sndq!
  147.                  */
  148.  
  149.     struct reseq *reseq;    /* Out-of-order segment queue */
  150.     struct timer timer;    /* Retransmission timer */
  151.     int32 rtt_time;        /* Stored clock values for RTT */
  152.     int32 rttseq;        /* Sequence number being timed */
  153.     int32 srtt;        /* Smoothed round trip time, milliseconds */
  154.     int32 mdev;        /* Mean deviation, milliseconds */
  155.  
  156.     int user;        /* User parameter (e.g., for mapping to an
  157.                  * application control block
  158.                  */
  159. };
  160. #define    NULLTCB    (struct tcb *)0
  161. /* TCP round-trip time cache */
  162. struct tcp_rtt {
  163.     int32 addr;        /* Destination IP address */
  164.     int32 srtt;        /* Most recent SRTT */
  165.     int32 mdev;        /* Most recent mean deviation */
  166. };
  167. #define    NULLRTT    (struct tcp_rtt *)0
  168. extern struct tcp_rtt Tcp_rtt[];
  169.  
  170. /* TCP statistics counters */
  171. struct tcp_stat {
  172.     int16 runt;        /* Smaller than minimum size */
  173.     int16 checksum;        /* TCP header checksum errors */
  174.     int16 conout;        /* Outgoing connection attempts */
  175.     int16 conin;        /* Incoming connection attempts */
  176.     int16 resets;        /* Resets generated */
  177.     int16 bdcsts;        /* Bogus broadcast packets */
  178. };
  179. extern struct mib_entry Tcp_mib[];
  180. #define    tcpRtoAlgorithm    Tcp_mib[1].value.integer
  181. #define    tcpRtoMin    Tcp_mib[2].value.integer
  182. #define    tcpRtoMax    Tcp_mib[3].value.integer
  183. #define    tcpMaxConn    Tcp_mib[4].value.integer
  184. #define    tcpActiveOpens    Tcp_mib[5].value.integer
  185. #define tcpPassiveOpens    Tcp_mib[6].value.integer
  186. #define    tcpAttemptFails    Tcp_mib[7].value.integer
  187. #define    tcpEstabResets    Tcp_mib[8].value.integer
  188. #define    tcpCurrEstab    Tcp_mib[9].value.integer
  189. #define    tcpInSegs    Tcp_mib[10].value.integer
  190. #define    tcpOutSegs    Tcp_mib[11].value.integer
  191. #define    tcpRetransSegs    Tcp_mib[12].value.integer
  192. #define    tcpInErrs    Tcp_mib[14].value.integer
  193. #define    tcpOutRsts    Tcp_mib[15].value.integer
  194. #define    tcpChkSumErrs    Tcp_mib[16].value.integer
  195. #define    NUMTCPMIB    16
  196.  
  197. extern struct tcb *Tcbs[];
  198. extern int16 Tcp_mss;
  199. extern int16 Tcp_window;
  200. extern int32 Tcp_irtt;
  201. extern int Tcp_trace;
  202. extern int Tcp_retry;
  203. extern char *Tcpstates[];
  204. extern char *Tcpreasons[];
  205.  
  206. /* In tcpcmd.c: */
  207. void st_tcp __ARGS((struct tcb *tcb));
  208.  
  209. /* In tcphdr.c: */
  210. struct mbuf *htontcp __ARGS((struct tcp *tcph,struct mbuf *data,
  211.     struct pseudo_header *ph));
  212. int ntohtcp __ARGS((struct tcp *tcph,struct mbuf **bpp));
  213.  
  214. /* In tcpin.c: */
  215. void reset __ARGS((struct ip *ip,struct tcp *seg));
  216. void send_syn __ARGS((struct tcb *tcb));
  217. void tcp_input __ARGS((struct mbuf *bp,struct ip *ip,int rxbroadcast));
  218. void tcp_icmp __ARGS((int32 source,int32 dest,char type,char code,struct mbuf **bpp));
  219.  
  220. /* In tcpsubr.c: */
  221. void close_self __ARGS((struct tcb *tcb,int reason));
  222. struct tcb *create_tcb __ARGS((struct connection *conn));
  223. void link_tcb __ARGS((struct tcb *tcb));
  224. struct tcb *lookup_tcb __ARGS((struct connection *conn));
  225. void rtt_add __ARGS((int32 addr,int32 rtt));
  226. struct tcp_rtt *rtt_get __ARGS((int32 addr));
  227. int seq_ge __ARGS((int32 x,int32 y));
  228. int seq_gt __ARGS((int32 x,int32 y));
  229. int seq_le __ARGS((int32 x,int32 y));
  230. int seq_lt __ARGS((int32 x,int32 y));
  231. int seq_within __ARGS((int32 x,int32 low,int32 high));
  232. void setstate __ARGS((struct tcb *tcb,int newstate));
  233. void unlink_tcb __ARGS((struct tcb *tcb));
  234.  
  235. /* In tcpout.c: */
  236. void tcp_output __ARGS((struct tcb *tcb));
  237.  
  238. /* In tcptimer.c: */
  239. int32 backoff __ARGS((int n));
  240. void tcp_timeout __ARGS((void *p));
  241.  
  242. /* In tcpuser.c: */
  243. int close_tcp __ARGS((struct tcb *tcb));
  244. int del_tcp __ARGS((struct tcb *tcb));
  245. int kick __ARGS((int32 addr));
  246. int kick_tcp __ARGS((struct tcb *tcb));
  247. struct tcb *open_tcp __ARGS((struct socket *lsocket,struct socket *fsocket,
  248.     int mode,int16 window,
  249.     void (*r_upcall) __ARGS((struct tcb *tcb,int cnt)),
  250.     void (*t_upcall) __ARGS((struct tcb *tcb,int cnt)),
  251.     void (*s_upcall) __ARGS((struct tcb *tcb,int old,int new)),
  252.     int tos,int user));
  253. int recv_tcp __ARGS((struct tcb *tcb,struct mbuf **bpp,int16 cnt));
  254. void reset_all __ARGS((void));
  255. void reset_tcp __ARGS((struct tcb *tcb));
  256. int send_tcp __ARGS((struct tcb *tcb,struct mbuf *bp));
  257. char *tcp_port __ARGS((int16 n));
  258. int tcpval __ARGS((struct tcb *tcb));
  259.  
  260. #endif    /* NULLTCB */
  261.